package com.amado.easyui2.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.amado.easyui2.dao.CoachStaffDao;
import com.amado.easyui2.domain.CoachStaffEntity;
import com.amado.easyui2.exception.ApiException;
import com.amado.easyui2.enums.ApiErrorEnum;
import com.amado.easyui2.service.CoachStaffService;
import com.amado.easyui2.vo.Page;
@Service
public class CoachStaffServiceImpl implements CoachStaffService {
	@Autowired
	private CoachStaffDao coachStaffDao;
	
	@Override
	public void add(CoachStaffEntity cn) {
		if(cn==null) {
			throw new ApiException(ApiErrorEnum.ERROR_100);
		}
		CoachStaffEntity returnCn=coachStaffDao.getByCodeName(cn.getCoachName());
		if(returnCn!=null) {
			throw new ApiException(ApiErrorEnum.ERROR_1001);
		}
		coachStaffDao.add(cn);
	}

	@Override
	public List<CoachStaffEntity> list() {
		// TODO Auto-generated method stub
		return coachStaffDao.listAll();
	}

//	@Override
//	public void delete(List<Long> id) {
//		coachStaffDao.delete(id);
//		
//	}

	@Override
	public void update(CoachStaffEntity cn) {
		coachStaffDao.update(cn);
		
	}

	@Override
	public CoachStaffEntity getCoach(Long id) {
		return coachStaffDao.getCoach(id);
	}

	@Override
	public Page<CoachStaffEntity> listAll(String cn, String cIC, Page page) {
		int total = coachStaffDao.listAllCount(cn, cIC);
		Page<CoachStaffEntity> newPage  = new Page<>();
		newPage.setTotal(total);
		newPage.setRows(coachStaffDao.listAll(cn, cIC, page));
		return newPage;
	}

	@Override
	public void delete(List<Long> id) {
		coachStaffDao.delete(id);
		
	}
	
}
